package com.example.infowall02.service.impl;

import com.example.infowall02.domain.Admin;
import com.example.infowall02.mapper.AdminMapper;
import com.example.infowall02.service.AdminService;
import com.example.infowall02.utils.MD5Util;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminMapper adminMapper;

    // 登录
    @Override
    public Admin login(String name, String password, String email) {
        return adminMapper.findAdminByUsernameAndPassword(name, MD5Util.md5(password),email);
    }
    // 注册
    @Override
    public Admin register(String name, String password, String email) {
        if(adminMapper.existsByAdminName(name)){
            return null;
        }
        if(adminMapper.insertAdmin(name, MD5Util.md5(password),email)){
            return adminMapper.findAdminByUsernameAndPassword(name, MD5Util.md5(password),email);
        }
        return null;
    }
}
